<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    /**
        显示登陆页面
     */


    public function  index(){
        return view('admin.login.index');

    }
      /*
        退出
    */

    public function logout(){
             \Auth::guard('admin')->logout();
        return redirect('/admin/login');
    }

     /**
        实现登陆功能
     */
    public function login()
    {
        
        $this->validate(request(),[
                'name'=>'required',
                'password'=>'required',

        ]);
        $user=[

                'name'=>request('name'),
                  'password'=>request('password'),   

        ];
    
        if(\Auth::guard('admin')->attempt($user)){
              return redirect('/admin/index');
        };

        return back()->withErrors('email and password are eroors');

        
    }

}
